package vn.anhqn.englishsentensetranslator.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import vn.anhqn.englishsentensetranslator.R;
import vn.anhqn.englishsentensetranslator.model.Sentense;
import vn.anhqn.englishsentensetranslator.model.SentenseDelete;
import vn.anhqn.englishsentensetranslator.widget.HeverticalTextView;

public class SentenseDeletaAdapter extends BaseAppAdapter<SentenseDelete> implements OnCheckedChangeListener {
	private List<Integer> listCheck = new ArrayList<Integer>();
	public SentenseDeletaAdapter(List<SentenseDelete> list, Context c) {
		super(list, c);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		ViewHolder holder = new ViewHolder();
		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.item_sentense_checkbox, null);
			holder.primaryTitle = (HeverticalTextView) view.findViewById(R.id.tv_primary);
			holder.secondTitle = (HeverticalTextView) view.findViewById(R.id.tv_second);
			holder.checkDel = (CheckBox) view.findViewById(R.id.check_del);
			holder.checkDel.setOnCheckedChangeListener(this);
			holder.checkDel.setTag(position);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		SentenseDelete item = getItem(position);
		holder.primaryTitle.setText(item.getFromLang());
		holder.secondTitle.setText(item.getToLang());
		holder.checkDel.setChecked(item.isChecked());
		return view;
	}

	private class ViewHolder {
		public HeverticalTextView primaryTitle;
		public HeverticalTextView secondTitle;
		public CheckBox checkDel;
	}


	public List<Integer> getListCheck() {
		return listCheck;
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if(isChecked)
			listCheck.add((Integer) buttonView.getTag());
		else
			listCheck.remove(buttonView.getTag());
	}
}
